﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class UIFollowTarget : MonoBehaviour {

    public GameObject Target;
    public float OffsetX;
    public float OffsetY;
    public float OffsetZ;

    private Vector3 Offset;

	// Use this for initialization
	void Start () {
        this.Offset = new Vector3(this.OffsetX, this.OffsetY, this.OffsetZ);
        
    }
	
	// Update is called once per frame
	void Update () {
        //Follow();
    }

    private void LateUpdate() {
        Follow();
    }

    private void Follow() {

        //transform.position = Camera.main.WorldToScreenPoint(this.Target.transform.position + this.Offset);
        //transform.position = Target.transform.position + this.Offset;

        float t1 = Time.realtimeSinceStartup;
        transform.position = Target.transform.position + this.Offset;
        float t2 = Time.realtimeSinceStartup;
        transform.position = Camera.main.WorldToScreenPoint(this.Target.transform.position + this.Offset);
        float t3 = Time.realtimeSinceStartup;
        //print(Target.name + "_s: " + (t2 - t1) + "--" + ", f: " + (t3 - t2));
    }
}
